const BASE_URL = "https://tea.qingnian8.com/api/bizhi"

export const request = (conf = {}) => {
	//解构形参，获取相应的实参
	let {
		url,
		method = "GET",
		data = {},
		header = {}
	} = conf

	//为请求报文添加初始头部信息
	header["access-key"] = 17551598853

	//修改url参数
	url = BASE_URL + url

	return new Promise((resolve, reject) => {
		uni.request({
			url,
			method,
			data,
			header,
			success: res => {
				if (res.data.errCode === 0)
					resolve(res.data)
				else if (res.data.errCode === 400) {
					uni.showModal({
						title: "错误提示",
						content: res.data.errMsg,
						showCancel: false
					})
					reject(res.data)
				}
				else{
					uni.showToast({
						title:res.data.errMsg,
						icon:"none"
					})
					reject(res.data)
				}
			},
			fail: err => {
				reject(err)
			}
		})
	})
}